import { reqCategory2List } from "@/api/goods/attr";
import { ICateOne } from "@/types/attr";
import { createSlice } from "@reduxjs/toolkit";
const twoSlice=createSlice({
    name:'categoryTwo',
    initialState:{
        value:[] as ICateOne[]
    },
    reducers:{
        saveCateTwo:(state,{payload})=>{
            state.value=payload
        }
    }
})

let {saveCateTwo}=twoSlice.actions

// 定义获取二级分类
export const addCategoryTwo=(category1Id:string)=>{

    return async(dispatch:any)=>{
     const res=   await reqCategory2List(category1Id)
     if(res.code===200){
        dispatch(saveCateTwo(res.data))
     }
    }
}

export default twoSlice.reducer